package resp

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"proxy_resource_test/utils"
	"time"
)

const (
	Success             = 0
	CommonError         = -1    // 错误
	SignError           = 10001 // 签名错误
	ServerBusy          = 15002 //服务繁忙
	ParamFormatError    = 10001 // 参数错误
	HeaderParamError    = 10002 // header参数错误   header invalid
	SessionExpireOrNone = 10003 // 请先登录
	SessionError        = 10004 // session报错
	RequestQpsTooHigh   = 8005

	// 邮箱相关错误
	EmailYetRegister           = 10116 // 邮箱已注册过
	EmailFormatError           = 10110 // 邮箱已注册过
	UserInexistence            = 10111 // 用户不存在
	EmailBindError             = 10112 // 邮箱绑定失败
	EmailFormatInNotTheCorrect = 10113
	EmailSendFail              = 10114
	EmailNotToBeRegister       = 10115
	EmailDeletedError          = 10117 // 邮箱已删除
	EmailAdminDeletedError     = 10119 // 邮箱已删除
	EmailFiveRegError          = 10118 // 邮箱已删除

	CaptchaCodeSendError      = 10121 // 验证码发送失败
	CaptchaCodeSendFrequently = 10122 // 验证码发送过于频繁
	CaptchaCodeError          = 10123 // 验证码错误

	SessionCreateError     = 10130 // 登录失败
	UserCreateError        = 10131 // 注册失败
	NotAffirmUserAgreement = 10132 // 未确认用户协议

	PasswordFormatError = 10140 // 密码格式只能为数字,字母, _
	PasswordWrong       = 10141 // 密码错误

	// 订单相关
	TixianError         = 10200 // 提现失败
	TixianInReviewError = 10201 // 提现失败
	TixianPayTyoeError  = 10202 // 提现失败

	// 更新相关
	NotUpdate = 10300 // 不需要更新

	GoogleAuthError  = 10400 // 谷歌授权失败
	GoogleLoginError = 10401 // 授权登录失败

	NotMeetingStandards = 10501 // 未达标
	Received            = 10502 // 已领取

	// 消息通知
	InvalidNotification = 10601 // 该消息通知无效

	PaypalPayeeToken   = 11001 // token 异常
	PaypalPayeeErr     = 11002 // token 异常
	PaypalPayeeSaltErr = 11003
	PaypalPayeeMdEnErr = 11005
	PaypalPayeeBusy    = 11006
)

func Json(c *gin.Context, code int, msg string, data interface{}) {
	c.JSON(http.StatusOK, gin.H{
		"code": code,
		"msg":  utils.Ucfirst(msg),
		"data": data,
		"time": time.Now().Unix(),
	})
	return
}

func JsonInternalErr(c *gin.Context, code int, msg string, data interface{}) {
	c.JSON(http.StatusInternalServerError, gin.H{
		"code": code,
		"msg":  utils.Ucfirst(msg),
		"data": data,
		"time": time.Now().Unix(),
	})
	return
}
